﻿package away3d.core.base.data ;



/**
* Face value object.
*/
class Face
{
    
    
    private var _vertices:      Vector<Float> ;
    private var _uvs:           Vector<Float> ;
    private var _faceIndex:     Int ;
    private var _v0Index:       Int ;
    private var _v1Index:       Int ;
    private var _v2Index:       Int ;
    private var _uv0Index:      Int ;
    private var _uv1Index:      Int ;
    private var _uv2Index:      Int ;
    
    
    
    /**
     * Creates a new <code>Face</code> value object.
     *
     * @param    vertices        [optional] 9 entries long Vector<Float> representing the x, y and z of v0, v1, and v2 of a face
     * @param    uvs            [optional] 6 entries long Vector<Float> representing the u and v of uv0, uv1, and uv2 of a face
     */
    public function new( ?vertices: Vector<Float> = null, ?uvs: Vector<Float> = null )
    {
        
        _vertices = vertices || Vector<Float>( [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0] ) ;
        _uvs = uvs || Vector<Float>( [0.0,0.0,0.0,0.0,0.0,0.0] ) ;
        
    }
    
    
    //uvs
    /**
     * To set uv values for either uv0, uv1 or uv2.
     * @param    index        The id of the uv ( 0, 1 or 2 )
     * @param    u            The horizontal coordinate of the texture value.
     * @param    v            The vertical coordinate of the texture value.
     */
    private function set_UVat( index: Int, u: Float, v: Float )
    {
        
        var ind:Int         = ( index*2 ) ;
        _uvs[ ind ]         = u ;
        _uvs[ ind + 1 ]     = v ;
        
    }
    
    
    public var faceIndex( get_faceIndex, set_faceIndex ) : Int ;
    
    
    /**
     * To store a temp index of a face during a loop
     * @param    ind        The index
     */
    private function set_faceIndex( ind: Int ) : Int
    {
        
        _faceIndex = ind ;
        return ind ;
        
    }
    
    
    /**
     * @return            Returns the tmp index set for this Face object
     */
    private function get_faceIndex(): Int
    {
        
        return _faceIndex ;
        
    }
    
    
    public var uv0Index( get_uv0Index, set_uv0Index ) : Int ; 
    
    
    //uv0
    /**
     * the index set for uv0 in this Face value object
     * @param    ind        The index
     */
    private function set_uv0Index( ind: Int ) : Int
    {
        
        _uv0Index ;
        return ind ;
        
    }
    
    
    /**
    * @return return the index set for uv0 in this Face value object
    */
    private function get_uv0Index() : Int
    {
        
        return _uv0Index ;
        
    }
    
    
    /**
     * uv0 u and v values
     * @param    u        The u value
     * @param    v        The v value
     */
    public function setUv0Value( u: Float, v: Float  )
    {
        _uvs[ 0 ] = u ;
        _uvs[ 1 ] = v ;
    }
    
    
    public var uv0u( get_uv0u, null) : Float ;
    
    
    /**
    * @return return the u value of the uv0 of this Face value object
    */
    private function get_uv0u() : Float
    {
        
        return _uvs[ 0 ] ;
        
    }
    
    
    public var uv0u( get_uv0v, null) : Float ;
    
    
    /**
    * @return return the v value of the uv0 of this Face value object
    */
    private function get_uv0v() : Float
    {
        
        return _uvs[ 1 ] ;
        
    }
    
    
    public var uv1Index( get_uv1Index, set_uv1Index ) : Int ;
    
    
    //uv1
    /**
     * the index set for uv1 in this Face value object
     * @param    ind        The index
     */
    private function set_uv1Index( ind: Int )
    {
        
        _uv1Index = ind;
        return ind ;
        
    }
    
    
    /**
    * @return Returns the index set for uv1 in this Face value object
    */
    private function get_uv1Index() : Int
    {
        
        return _uv1Index ;
        
    }
    
    
    /**
     * uv1 u and v values
     * @param    u        The u value
     * @param    v        The v value
     */
    public function setUv1Value( u: Float, v: Float  )
    {
        
        _uvs[ 2 ] = u ;
        _uvs[ 3 ] = v ;
        
    }
    
    
    public var uv1u( get_uv1u, set_uv1u ) : Float ;
    
    
    /**
    * @return Returns the u value of the uv1 of this Face value object
    */
    private function get_uv1u() : Float
    {
        
        return _uvs[ 2 ] ;
        
    }
    
    
    public var uv1v( get_uv1v, null ) : Float ;
    
    
    /**
    * @return Returns the v value of the uv1 of this Face value object
    */
    private function get_uv1v() : Float
    {
        
        return _uvs[ 3 ] ;
        
    }
    
    
    public var uv2Index( get_uv2Index, set_uv2Index ) : Int ;
    
    
    //uv2
    /**
     * the index set for uv2 in this Face value object
     * @param    ind        The index
     */
    private function set_uv2Index( ind: Int )
    {
        
        _uv2Index = ind ;
        return ind ;
        
    }
    
    
    /**
    * @return return the index set for uv2 in this Face value object
    */
    private function get_uv2Index() : Int
    {
        
        return _uv2Index ;
        
    }
    
    
    /**
     * uv2 u and v values
     * @param    u        The u value
     * @param    v        The v value
     */
    private function setUv2Value( u:Float, v:Float  )
    {
        
        _uvs[ 4 ] = u ;
        _uvs[ 5 ] = v ;
        
    }
    
    
    public var uv2u( get_uv2u, null ) : Float ;
    
    
    /**
    * @return return the u value of the uv2 of this Face value object
    */
    private function get_uv2u() : Float
    {
        
        return _uvs[ 4 ] ;
        
    }
    
    
    public var uv2v( get_uv2v, null ) : Float ;
    
    
    /**
    * @return return the v value of the uv2 of this Face value object
    */
    private function get_uv2v() : Float
    {
        
        return _uvs[5] ;
        
    }
    
    
      //vertices
    /**
     * To set uv values for either v0, v1 or v2.
     * @param    index        The id of the uv ( 0, 1 or 2 )
     * @param    x            The x value of the vertex.
     * @param    y            The y value of the vertex.
     * @param    z            The z value of the vertex.
     */
    public function setVertexAt( index: Int, x: Float, y: Float, z: Float )
    {
        
        var ind = ( index*3 ) ;
        _vertices[ ind ]        = x ;
        _vertices[ ind + 1 ]    = y ;
        _vertices[ ind + 2 ]    = z ;
        
    }
    
    
    public var v0Index( get_v0Index, set_v0Index ) : Int ;
    
    
    //v0
    /**
     * set the index value for v0
     * @param    ind            The index value to store
     */
    private function set_v0Index( ind: Int )
    {
        
        _v0Index = ind;
        return ind ;
        
    }
    
    
    /**
    * @return Returns the index value of the v0 stored in the Face value object
    */
    private function get_v0Index() : Int
    {
        
        return _v0Index ;
        
    }
    
    
    public var v0( get_v0, null ) : Vector<Float> ; 
    
    
    /**
    * @return Returns a Vector<Float> representing the v0 stored in the Face value object
    */
    private function get_v0() : Vector<Float>
    {
        
        return Vector( [_vertices[ 0 ], _vertices[ 1 ], _vertices[ 2 ] ] ) ;
        
    }
    
    
    public var v0x( get_v0x, null ) : Vector<Float> ; 
    
    
    /**
    * @return Returns the x value of the v0 stored in the Face value object
    */
    private function get_v0x() : Float
    {
        
        return _vertices[ 0 ] ;
        
    }
    
    
    public var v0y( get_v0y, null ) : Vector<Float> ; 
    
    
    /**
    * @return Returns the y value of the v0 stored in the Face value object
    */
    private function get_v0y():Float
    {
        
        return _vertices[ 1 ] ;
        
    }
    
    
    public var v0z( get_v0z, null ) : Vector<Float> ; 
    
    
    /**
    * @return Returns the z value of the v0 stored in the Face value object
    */
    private function get_v0z():Float
    {
        
        return _vertices[ 2 ] ;
        
    }
    
    
    public var v1Index( get_v1Index, set_v1Index ) : Int ;
    
    
    //v1
    /**
     * set the index value for v1
     * @param    ind            The index value to store
     */
    private function set_v1Index( ind: Int )
    {
        
        _v1Index = ind;
        return ind ;
        
    }
    
    
    /**
    * @return Returns the index value of the v1 stored in the Face value object
    */
    private function get_v1Index(): Int
    {
        
        return _v1Index ;
        
    }
    
    
    public var v1Index( get_v1, null ) : Vector<Float> ;
    
    
    /**
    * @return Returns a Vector<Float> representing the v1 stored in the Face value object
    */
    private function get_v1() : Vector<Float>
    {
        
        return Vector( [ _vertices[ 3 ], _vertices[ 4 ], _vertices[ 5 ] ] ) ;
        
    }
    
    
    public var v1x( get_v1x, null ) : Float ;
    
    
    /**
    * @return Returns the x value of the v1 stored in the Face value object
    */
    private function get_v1x():Float
    {
        
        return _vertices[ 3 ] ;
        
    }
    
    
    public var v1y( get_v1y, null ) : Float ;
    
    
    /**
    * @return Returns the y value of the v1 stored in the Face value object
    */
    private function get_v1y() : Float
    {
        
        return _vertices[ 4 ] ;
        
    }
    
    
    public var v1z( get_v1z, null ) : Float ;
    
    
    /**
    * @return Returns the z value of the v1 stored in the Face value object
    */
    private function get_v1z() : Float
    {
        
        return _vertices[ 5 ] ;
        
    }
    
    
    public var v2Index( get_v2Index, set_v2Index ) : Int ;
    
    
    //v2
    /**
     * set the index value for v2
     * @param    ind            The index value to store
     */
    private function set_v2Index( ind: Int )
    {
        
        _v2Index = ind;
        return ind ;
        
    }
    
    
    /**
    * @return return the index value of the v2 stored in the Face value object
    */
    private function get_v2Index(): Int
    {
        
        return _v2Index ;
        
    }
    
    
    public var v2( get_v2, null ) : Vector<Float>
    
    
    /**
    * @return Returns a Vector<Float> representing the v2 stored in the Face value object
    */
    private function get_v2() : Vector<Float>
    {
        
        return Vector<Float>( [ _vertices[ 6 ], _vertices[ 7 ], _vertices[ 8 ] ] ) ;
        
    }
    
    
    public var v2x( get_v2x, null ) : Vector<Float>
    
    
    /**
    * @return Returns the x value of the v2 stored in the Face value object
    */
    private function get_v2x():Float
    {
        
        return _vertices[ 6 ] ;
        
    }
    
    
    public var v2y( get_v2y, null ) : Vector<Float>
    
    
    /**
    * @return Returns the y value of the v2 stored in the Face value object
    */
    private function get_v2y():Float
    {
        
        return _vertices[ 7 ] ;
        
    }
    
    
    public var v2z( get_v2z, null ) : Vector<Float>
    
    
    /**
    * @return Returns the z value of the v2 stored in the Face value object
    */
    private function get_v2z():Float
    {
        
        return _vertices[ 8 ] ;
        
    }
    
    
    /**
     * returns a new Face value Object
     */
    public function clone():Face
    {
        
        var nVertices   = Vector(   [ _vertices[ 0 ], _vertices[ 1 ], _vertices[ 2 ]
                                    , _vertices[ 3 ], _vertices[ 4 ], _vertices[ 5 ]
                                    , _vertices[ 6 ], _vertices[ 7 ], _vertices[ 8 ]
                                    ] ) ;
        
        var nUvs        = Vector(   [ _uvs[ 0 ], _uvs[ 1 ]
                                    , _uvs[ 2 ], _uvs[ 3 ]
                                    , _uvs[ 4 ], _uvs[ 5 ] 
                                    ] ) ;
        
        return new Face( nVertices, nUvs ) ;
        
    }
    
    
}
